<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td>
            <span class="preview"></span>
        </td>
        <td>
            <p class="name">{%=file.name%}</p>
            <strong class="error text-danger"></strong>
        </td>
        <td>
            <p class="size">Processing...</p>
            <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
        </td>
        <td>
            {% if (!i && !o.options.autoUpload) { %}
                <button class="btn btn-primary start" disabled>
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>Start</span>
                </button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning cancel">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>Cancel</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>

<!-- function used by the following template -->
<script type="text/javascript">
  function setAllResourceTypes() {
    var firstResourceType = $(".resource_type_dropdown")[0].value;
    $(".resource_type_dropdown").each(function(index, element) {
      element.value = firstResourceType;
    });
  }
</script>

<!-- The template to display files available for download -->
<script id="batch-template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
          <div class="row">
            <div class="col-sm-6 name">
                <span>{%=file.name%}</span>
                <input type="hidden" name="uploaded_files[]" value="{%=file.id%}">
            </div>
            <div class="col-sm-6">
              {% if (file.error) { %}
                  <div><span class="label label-danger">Error</span> {%=file.error%}</div>
              {% } %}
              <span class="size">{%=o.formatFileSize(file.size)%}</span>
              <button class="btn btn-danger delete pull-right" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                  <i class="glyphicon glyphicon-trash"></i>
                  <span>Delete</span>
              </button>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-12 form-horizontal">
              <div class="form-group">
                <label for="title_{%=file.id%}" class="col-sm-5 control-label">Display label</label>
                <div class="col-sm-7">
                  <input type="text" class="form-control" name="title[{%=file.id%}]" id="title_{%=file.id%}" value="{%=file.name%}">
                </div>
                <label for="resource_type_{%=file.id%}" class="col-sm-5 control-label">Resource Type</label>
                <div class="col-sm-7">
                  <select class="form-control resource_type_dropdown" name="resource_type[{%=file.id%}]" id="resource_type_{%=file.id%}" value="{%=file.name%}">
                    <% ResourceTypesService.select_options.each do |type| %>
                      <option value="<%= type[0] %>"><%= type[1] %></option>
                    <% end %>
                  </select>
                  <!-- TODO: Why is the button drawn for all files? -->
                  {% if (i == 0) { %}
                    <button class="btn pull-right resource_type_button" onClick="setAllResourceTypes(); return false;">Set all to this Resource Type</button>
                  {% } %}
                </div>
              </div>
            </div>
          </div>
        </td>
    </tr>
{% } %}
</script>

<!-- Simpler display of files available for download. Originally from curation_concerns/base/_form_files -->
<!-- TODO: further consolidate with template-download above -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
            <span class="preview">
                {% if (file.thumbnailUrl) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
                {% } %}
            </span>
        </td>
        <td>
            <p class="name">
                {% if (file.url) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                {% } else { %}
                    <span>{%=file.name%}</span>
                {% } %}
                <input type="hidden" name="uploaded_files[]" value="{%=file.id%}">
            </p>
            {% if (file.error) { %}
                <div><span class="label label-danger">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=o.formatFileSize(file.size)%}</span>
        </td>
        <td>
            <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                <i class="glyphicon glyphicon-trash"></i>
                <span>Delete</span>
            </button>
        </td>
    </tr>
{% } %}
</script>
